
//<!--Created by 王童 on 2018/5/24-->
package cn.yunhe.services.impl;

import cn.yunhe.dao.WtStuDao;
import cn.yunhe.entity.Course;
import cn.yunhe.entity.Point;
import cn.yunhe.entity.Problem;
import cn.yunhe.services.WtIStuServices;
import cn.yunhe.util.StringToMap;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/5/23.
 */
@Service("stuServices")
public class WtStuServices implements WtIStuServices {
    @Resource
    private WtStuDao stuDao;

    @Override
    public List<Course> getAlls() {
        return stuDao.getAlls();
    }

    @Override
    public List<Point> getAllPoint() {
        return stuDao.getAllPoint();
    }

    @Override
    public List<Problem> getGrade() {
        return stuDao.getGrade();
    }

    @Override
    public Page queryLikeProblems(Map<String, Object> cond) {
        //
        Page page=new Page();
        page.setTotal(stuDao.getLikeProblemsCount(cond));
        int pageSize = Integer.parseInt(String.valueOf(cond.get("pageSize")));
        page.setPageSize(pageSize);
        // 从请求参数中获取当前页码
        int curPageNum = Integer.parseInt(String.valueOf(cond.get("pageNum")));
        page.setPageNum(curPageNum);
        //动态计算总页数(总记录数 除以 每页大小，加上  总页数 求余 每页大小，如果余数不为0，则 加 1，否则 加 0 )
        page.setPageNum((int) (page.getTotal() / pageSize + (page.getTotal() % pageSize == 0 ? 0 : 1)));
        //根据条件查询符合的用户列表记录，赋值给page的result变量
        page = PageHelper.startPage(curPageNum, pageSize);
        List<Problem> list = stuDao.getLikeProblems(cond);
        for(int i=0;i<list.size();i++){
            list.get(i).setPro_mapname(StringToMap.stringToMap(list.get(i).getPro_choice()));
        }
        return page;
    }



}
